home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_001 / requesters / menu.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  29KB  |  860 lines

  1. /**************************************************************************
  2. *     M E N U   E X A M P L E    P R O G R A M   -   JOHN DRAPER
  3. *
  4. *    This program demonstrates the use of menus.   It is constructed so
  5. *  pieces can me "Plucked out" and used in other programs.
  6. *
  7. *    The menu structures are declared and initialized much like the
  8. *  existing Amiga demo programs,  however,  the MenuItem structures
  9. *  are initialized by a function from easily changed arrays.   This
  10. *  combines "Best of both worlds".   Only a single routine is needed to
  11. *  initialize the MenuItem structures, and yet the source code won't
  12. *  be un-necessarily cluttered by having each of the MenuItem structures
  13. *  declared and initialized,  thus keeping the program size to within
  14. *  reasonable limits.   This program will compile on Both Lattice C
  15. *  and Aztec C (Soon to be released).  Remove the #define AZTEC
  16. *
  17. *    This isn't the most efficient piece of C code I've written,  as if
  18. *  I write a lot of C code,  It only shows what is involved in creating
  19. *  menus,  and taking menu actions.
  20. ***************************************************************************/
  21.  
  22. #include <exec/types.h>
  23. #include <exec/nodes.h>
  24. #include <exec/lists.h>
  25. #include <exec/ports.h>
  26. #include <exec/devices.h>
  27. #include <devices/keymap.h>
  28. #include <graphics/regions.h>
  29. #include <graphics/copper.h>
  30. #include <graphics/gels.h>
  31. #include <graphics/gfxbase.h>
  32. #include <graphics/gfx.h>
  33. #include <graphics/clip.h>
  34. #include <graphics/view.h>
  35. #include <graphics/rastport.h>
  36. #include <graphics/layers.h>
  37. #include <intuition/intuition.h>
  38. #include <hardware/blit.h>
  39.  
  40. /***************************************************************************
  41. *    Early beta-test versions of Manx C had a bug which caused a system
  42. *    crash with certain void constructs.  This same compiler does NOT
  43. *    predefine "AMIGA", so we use this def to remap voids to int.
  44. *    Also note that "VOID" is defined in <exec/types.h>.
  45. ***************************************************************************/
  46.  
  47. #ifndef AMIGA
  48. #undef VOID            /** Get rid of old definition **/
  49. #define VOID int        /** Make void's int's instead **/
  50. #endif
  51.  
  52. /***************************************************************************
  53. *              I M P O R T A N T         C O N S T A N T S
  54. ***************************************************************************/
  55.  
  56. #define MAXPLANES    6        /**  Max number of bitplanes we will need ***/
  57. #define MAX_WIDTH  128        /**  Max number of Pixels wide for sprite   */
  58. #define MAX_HEIGHT 128        /**  Max number of pixels high for sprite   */
  59. #define NL 0
  60.  
  61. #define REDP 3
  62. #define BLKP 2
  63. #define WHTP 1
  64. #define BLUP 0
  65.  
  66. /*** CLOSE FLAGS FOR VARIOUS THINGS ***/
  67.  
  68. long   mask = 0;
  69. #define INTUITION 0x00000001
  70. #define GRAPHICS  0x00000002
  71. #define SCREEN    0x00000004
  72. #define WINDOW    0x00000008
  73. #define COLORMAP  0x00000010
  74. #define MENU      0x00000020
  75.  
  76.  
  77.  
  78. int  we_add = TRUE;      /* We add a proportional gadget for first time */
  79.  
  80. /***************************************************************************
  81.                  F U N C T I O N     D E C L A R A T I O N S
  82. ***************************************************************************/
  83.  
  84.  
  85. extern VOID *OpenLibrary();
  86. extern struct Window *OpenWindow();
  87. extern struct IntuiMessage *GetMsg();
  88. extern VOID exit();
  89.  
  90. static VOID close_things();
  91. static VOID NewMenu();
  92. static VOID domenu();
  93. static VOID auto_req();
  94. static VOID do_req();
  95.  
  96. /*
  97.  * For portability between compilers with 32 bit ints and thoses with
  98.  * 16 bit ints, the following referenced functions are declared as returning
  99.  * long, which is 32 bits for most compilers with 16 bit ints.
  100.  *
  101.  * Actually, I have not really checked the library documentation to find
  102.  * out if any of these actually return pointers.
  103.  *
  104.  */
  105.  
  106. extern long RefreshGadgets();
  107. extern long SetMenuStrip();
  108. extern long AddGadget();
  109. extern long AutoRequest();
  110. extern long OpenWorkBench();
  111. extern long ClearMenuStrip();
  112. extern long ReplyMsg();
  113. extern long Wait();
  114. extern long InitRequester();
  115. extern long Request();
  116. extern long CloseLibrary();
  117. extern long DrawImage();
  118. extern long CloseWindow();
  119. extern long printf();
  120.  
  121.  
  122. /***************************************************************************
  123. *          I N T U I T I O N      G L O B A L      V A R S
  124. ***************************************************************************/
  125.  
  126. struct IntuitionBase *IntuitionBase;
  127. struct GfxBase *GfxBase;
  128. struct IntuiMessage *message;
  129. struct RastPort *rp;
  130. struct Window *w;
  131.  
  132. /***************************************************************************
  133. *           M I S C     G L O B A L      V A R I A B L E S
  134. ***************************************************************************/
  135.  
  136.  
  137. /***************************************************************************
  138.                      M E N U      D E F I N I T I O N S
  139. ***************************************************************************/
  140.  
  141. #define NUM_MENUS 3
  142.  
  143. /* Copies of this structure will get "stamped" into many more */
  144. /* Allocated later */
  145. struct IntuiText generic = {
  146.   0, 1,                        /* Bluepen, Whitepen */
  147.   JAM2, 5,                     /* mode,  LeftEdge */
  148.   0, NL,                       /* Top (to be filled later), Font */
  149.   NL,                          /* Name (to be filled later) */
  150.   NL                           /* Next one */
  151. };
  152.  
  153.  
  154. /* Menu numbers */
  155. #define FILE_MENU 0
  156. #define WIND_MENU 1
  157. #define REQS_MENU 2
  158.  
  159.  
  160. /* Menu Widths */
  161. #define FIL_WIDTH  60
  162. #define ITEM_WIDTH 70
  163. #define REQ_WIDTH 100
  164.  
  165. int item_widths[ NUM_MENUS ] = { 80, 96, 198 };
  166.  
  167. /* All items in these menus has the following flags set */
  168. #define BOX_FILL    ITEMTEXT | ITEMENABLED | HIGHBOX           /* File   */
  169. #define BLACK_FILL  ITEMTEXT | ITEMENABLED | HIGHCOMP          /* Wind   */
  170. #define HAS_CHECKS  ITEMTEXT | ITEMENABLED | HIGHBOX | CHECKIT /* Reqs   */
  171.  
  172.  
  173.                             /** BITPLANE MENU ITEM NAME POINTERS **/
  174. #define NUM_REQUESTS 6
  175. #define REQS1  0
  176. #define REQS2  1
  177. #define REQS3  2
  178. #define GAD_REQS 3
  179. #define TEX_REQS 4
  180. #define IMG_REQS 5
  181.  
  182. struct MenuItem req_items[NUM_REQUESTS];
  183. struct IntuiText req_names[NUM_REQUESTS];
  184.  
  185. char  *rqs_names[] = {
  186.    "  Auto Request 1",
  187.    "  Auto Request 2",
  188.    "  Auto Request 3",
  189.    "  Create Joystick gadget",
  190.    "  Custom Requester",
  191.    "  Requester with Images"
  192. };
  193.  
  194. struct Menu req_menu = {
  195.    NL,                             /* NO Next menu */
  196.    FIL_WIDTH + ITEM_WIDTH,         /* LeftEdge */
  197.    0, REQ_WIDTH, 10,               /* TopEdge, Width, Height */
  198.    MENUENABLED,                    /* Flags */
  199.    "Requestors",                   /* Menu name */
  200.    req_items                       /* Pointer to items list */
  201. };
  202.  
  203.                             /** OPTIONS MENU ITEM NAME POINTERS ***/
  204. #define NUM_WINDOWS 2
  205. #define INFO_ITEM 0
  206. #define GRA_ITEM 1
  207.  
  208. static struct MenuItem win_items[NUM_WINDOWS];
  209. static struct IntuiText win_text[NUM_WINDOWS];
  210.  
  211. char  *wind_names[] = {
  212.    "Information",           /* Write text into window, then close it */
  213.    "Graphics"               /* Draw various graphics images into window */
  214. };
  215.  
  216. struct Menu win_menu = {
  217.    &req_menu,               /* Pointer to next menu */
  218.    FIL_WIDTH,               /* LeftEdge */
  219.    0, ITEM_WIDTH, 10,       /* TopEdge, Width, Height */
  220.    MENUENABLED,             /* FLAGS */
  221.    "Windows",               /* Name of menu */
  222.     win_items               /* First item structure */
  223. };
  224.  
  225.  
  226.                             /** FILE MENU ITEMS  **/
  227. #define NUM_FILE_ITEMS 5
  228. #define NEW_ITEM       0
  229. #define OPEN_ITEM      1
  230. #define SAVE_ITEM      2
  231. #define SAVAS_ITEM     3
  232. #define QUIT_ITEM      4
  233.  
  234. struct MenuItem  file_items[NUM_FILE_ITEMS];
  235. struct IntuiText file_names[NUM_FILE_ITEMS];
  236.  
  237. char  *filemenu_names[] = {
  238.    "New",
  239.    "Open",
  240.    "Save",
  241.    "Save as..",
  242.    "Quit"
  243. };
  244.  
  245. struct Menu fmenu = {
  246.   &win_menu,                 /* Pointer to next menu */
  247.   0, 0, FIL_WIDTH, 10,       /* LeftEdge, TopEdge, Width, Height */
  248.   MENUENABLED,               /* FLAGS */
  249.   "File",                    /* Menu name */
  250.   file_items                 /* First item structure */
  251. };
  252.  
  253. /***************************************************************************
  254.                    AUTO REQUEST INTUITEXT STRUCTURES
  255. ***************************************************************************/
  256.  
  257. struct IntuiText AutoText = {
  258.    REDP,     WHTP,
  259.    JAM2,  5,
  260.    5,    NL,               /* A function puts string in this one */
  261.    (UBYTE *) "Simple AutoRequest",
  262.    NL
  263. };
  264.  
  265. /** TRUE TEXT **/
  266. struct IntuiText TRUEtext = {
  267.    BLUP,  WHTP,
  268.    JAM2,
  269.    7,                       /* LeftEdge */
  270.    3,                       /* TopEdge  */
  271.    NL,                      /* Default font */
  272.    (UBYTE *) "TRUE",        /* Text */
  273.    NL                       /* No pointer to next text */
  274. };
  275.  
  276. /** FALSE TEXT **/
  277. struct IntuiText FALSEtext = {
  278.    REDP,  WHTP,
  279.    JAM2,
  280.     7,                       /* LeftEdge */
  281.     3,                       /* TopEdge  */
  282.    NL,                       /* Default font */
  283.    (UBYTE *) "FALSE",        /* Text */
  284.    NL
  285. };
  286.  
  287. /***************************************************************************
  288.                CUSTOM REQUEST WITH TEXT, BORDERS, AND GADGETS
  289. ***************************************************************************/
  290.  
  291. /* Border for buttons */
  292. SHORT Pairs[] = {
  293.  0, 0,
  294.  51, 0,
  295.  51, 12,
  296.  0, 12,
  297.  0,  0
  298. };
  299.  
  300. #define NUM_PAIRS 5
  301. struct Border butt_border = {
  302.  -1,  -1,
  303.  BLUP, 0, JAM1,
  304.  NUM_PAIRS,
  305.  (SHORT *) Pairs,
  306.  NULL
  307. };
  308.  
  309. /* FALSE BUTTON TEXT AND GADGET */
  310. struct IntuiText negtext = {
  311.   REDP, WHTP, JAM2,
  312.   6, 2, NL,
  313.   (UBYTE *) "FALSE",
  314.   NL
  315. };
  316. #define FALSE_BUTT 1      /** GadgetID used to identify the action ***/
  317. struct Gadget offgad = {
  318.   NULL,
  319.   158, 46,                 /* LeftEdge, TopEdge     */
  320.   50, 11,                 /* Width,  Height        */
  321.   GADGHCOMP,              /* Flag                  */
  322.   RELVERIFY | ENDGADGET,  /* Activation            */
  323.   BOOLGADGET | REQGADGET, /* GadgetType            */
  324.   (APTR)&butt_border,     /* GadgetRender - Border */
  325.   NULL,                   /* SelectRender          */
  326.   &negtext,               /* "OK" text             */
  327.   NL, NL, FALSE_BUTT, NL          /* Mut Excl, Spec Info,  */
  328. };
  329.  
  330.  
  331. /* "TRUE" TEXT AND GADGET */
  332. struct IntuiText postext = {
  333.   BLKP, WHTP, JAM2,
  334.   6, 2, NL,
  335.   (UBYTE *) "TRUE",
  336.   NL
  337. };
  338. #define TRUE_BUTT 2
  339. struct Gadget ongad = {
  340.   &offgad,
  341.   30, 46,                 /* LeftEdge, TopEdge     */
  342.   50, 11,                 /* Width,  Height        */
  343.   GADGHCOMP,              /* Flag                  */
  344.   RELVERIFY | GADGIMMEDIATE,   /* Activation            */
  345.   BOOLGADGET | REQGADGET, /* GadgetType            */
  346.   (APTR)&butt_border,     /* GadgetRender - Border */
  347.   NULL,                   /* SelectRender          */
  348.   &postext,               /* "OK" text             */
  349.   NL, NL, TRUE_BUTT, NL   /* Mut Excl, Spec Info,  */
  350. };
  351.  
  352.  
  353. /* Outside Border of Requester */
  354. SHORT ReqPairs[] = {
  355.  5, 3,
  356.  247, 3,
  357.  247, 78,
  358.  5, 78,
  359.  5, 3
  360. };
  361.  
  362. struct Border out_border = {
  363.  -1, -1,
  364.  BLKP, 0, JAM1,
  365.  NUM_PAIRS,
  366.  (SHORT *) ReqPairs,
  367.  NULL
  368. };
  369.  
  370. /* Text structures for a regular SysRequest structure */
  371. struct IntuiText text = {
  372.   BLUP, WHTP, JAM2,
  373.   58, 5, NL,
  374.   (UBYTE *) "Regular requestor",
  375.   NL
  376. };
  377.  
  378. struct Requester req;     /* Custom Requester structure */
  379.  
  380. /***************************************************************************
  381.                    CUSTOM REQUEST IMAGE BOOLEAN GADGETS
  382.                    BIT IMAGES FOR THE IMAGE REQUESTER
  383. ***************************************************************************/
  384.  
  385. /** Image for the smiley face **/
  386. UWORD smile[] = {
  387. 0x0000, 0x0000, 0x001f, 0xf100, 0x0060, 0x0600, 0x0180, 0x0180,
  388. 0x0218, 0x1840, 0x0424, 0x2420, 0x0418, 0x1820, 0x0800, 0x0010,
  389. 0x0801, 0x8010, 0x0801, 0x8010, 0x0803, 0xc010, 0x0800, 0x0010,
  390. 0x0420, 0x0420, 0x0418, 0x1820, 0x0207, 0xe040, 0x0180, 0x0180,
  391. 0x0060, 0x0600, 0x001f, 0xf800, 0x0000, 0x0000, 0x0000, 0x0000
  392. };
  393.  
  394. struct Image smil_face = {
  395.  0, 0,                        /* Left, Top */
  396.  32, 20, 1,                   /* Width, Height, Depth */
  397.  &smile[0],                   /* Pointer to data above */
  398.  1, 0,                        /* PlanePick,  PlaneOnOff */
  399.  NULL                         /* Next Image */
  400. };
  401.  
  402.  
  403. /** Image for the face with the tongue **/
  404. UWORD tonge[] = {
  405. 0x0000, 0x0000, 0x001f, 0xf100, 0x0060, 0x0600, 0x0180, 0x0180,
  406. 0x0218, 0x1840, 0x0424, 0x2420, 0x0418, 0x1820, 0x0800, 0x0010,
  407. 0x0801, 0x8010, 0x0801, 0x8010, 0x0803, 0xc010, 0x0800, 0x0010,
  408. 0x040f, 0xf020, 0x0410, 0x0120, 0x0214, 0x2860, 0x018c, 0x3180,
  409. 0x0064, 0x2600, 0x001e, 0x7100, 0x0002, 0x6000, 0x0001, 0x8000
  410. };
  411.  
  412. struct Image tong_face = {
  413.  0, 0,                        /* Left, Top */
  414.  32, 20, 1,                   /* Width, Height, Depth */
  415.  &tonge[0],                   /* Pointer to data above */
  416.  1, 0,                        /* PlanePick,  PlaneOnOff */
  417.  NULL                         /* Next Image */
  418. };
  419.  
  420. struct IntuiText gag_me = {
  421.   BLKP, WHTP, JAM2,
  422.   -1, 21, NL,
  423.   (UBYTE *) "Click me",
  424.   NL
  425. };
  426.  
  427. #define FACE 3
  428. struct Gadget face_gad = {
  429.   NULL,
  430.   30, 18,                              /* LeftEdge, TopEdge     */
  431.   32, 20,                              /* Width,  Height        */
  432.   GADGHIMAGE | GADGIMAGE | GADGHIMAGE, /* Flag                  */
  433.   RELVERIFY | GADGIMMEDIATE,           /* Activation            */
  434.   BOOLGADGET | REQGADGET,              /* GadgetType            */
  435.   (APTR)&smil_face,                    /* GadgetRender - Border */
  436.   (APTR)&tong_face,                    /* SelectRender          */
  437.   &gag_me,                             /* "Gag me"              */
  438.   NL, NL, FACE, NL                       /* Mut Excl, Spec Info,  */
  439. };
  440.  
  441.  
  442. struct IntuiText stab_here = {
  443.   BLUP, WHTP, JAM2,
  444.   6, 2, NL,
  445.   (UBYTE *) "Stab here",
  446.   NL
  447. };
  448.  
  449. /* Border to the button */
  450. SHORT gag_pairs[] = {
  451. 0, 0,
  452. 80, 0,
  453. 80, 12,
  454. 0, 12,
  455. 0, 0
  456. };
  457.  
  458. struct Border gag_border = {
  459.  -1, -1,
  460.   BLKP, WHTP, JAM1,
  461.   NUM_PAIRS,
  462.   (SHORT *) gag_pairs,
  463.   NULL
  464. };
  465. #define STAB_BUTT 4
  466. struct Gadget stab = {
  467.   &face_gad,
  468.   130, 20,                /* LeftEdge, TopEdge     */
  469.   78, 11,                 /* Width,  Height        */
  470.   GADGHCOMP,              /* Flag                  */
  471.   RELVERIFY | ENDGADGET,  /* Activation            */
  472.   BOOLGADGET | REQGADGET, /* GadgetType            */
  473.   (APTR)&gag_border,     /* GadgetRender - Border */
  474.   NULL,                   /* SelectRender          */
  475.   &stab_here,             /* "Stab me"             */
  476.   NL, NL, STAB_BUTT, NL          /* Mut Excl, Spec Info,  */
  477. };
  478.  
  479. /*** Text which goes in the main requester ***/
  480. struct IntuiText imag_text = {
  481.   BLUP, WHTP, JAM2,
  482.   38, 7, NL,
  483.   (UBYTE *) "Gag me with the mouse",
  484.   NL
  485. };
  486.  
  487. struct Requester gag;
  488.  
  489. /***************************************************************************
  490. *                     J O Y    S T I C K    G A D G E T
  491. ***************************************************************************/
  492.  
  493. /*  Image for a custom proportional gadget */
  494.  
  495. UWORD joyimage[] = {
  496. 0x0000, 0x0000, 0x0180, 0x0660, 0x1818, 0x2004, 0x4002, 0x4002,
  497. 0x4002, 0x4002, 0x2004, 0x1818, 0x0660, 0x0180, 0x0000, 0x0000
  498. };
  499.  
  500.  
  501. struct Image joy_image = {
  502.   0, 0,                    /* LeftEdge, TopEdge */
  503.   16, 16, 1,               /* Width, Height, Depth */
  504.   &joyimage[0],           /* Pointer to bit image */
  505.   1,  0,                   /* PlanePick, Planeonoff */
  506.   NULL                     /* No other images */
  507. };
  508.  
  509. struct PropInfo joy_prop = {
  510.    FREEHORIZ | FREEVERT,            /* Want knob to go both vert and horiz */
  511.    0x8000,  0x8000,                 /* Want knob to be centered initially  */
  512.    0x800,   0x800,                  /* Smallest increment the knob can move */
  513.    150, 50,                         /* cWidth, cHeight - Container w & h */
  514.    1, 1,                            /* HPosres, VPotres - Pot increments */
  515.    0, 0                             /* Container borders  */
  516. };
  517.  
  518. #define CUST_KNOB 5
  519. struct Gadget JoyGadget = {
  520.    NL, 17, 140, 150, 50, GADGHCOMP, GADGIMMEDIATE | RELVERIFY,
  521.    PROPGADGET, (APTR)&joy_image, NL,
  522.    NL, NL, (APTR)&joy_prop, CUST_KNOB, NL
  523. };
  524.  
  525.  
  526. /***************************************************************************
  527. *                  N E W     W I N D O W     S T R U C T U R E
  528. ***************************************************************************/
  529.  
  530. struct NewWindow nw = {
  531.   0, 0,                  /*  Start position                               */
  532.   320, 200,              /*  width, height, depth                         */
  533.   0, 1,                  /*  detail, block pens                           */
  534.   CLOSEWINDOW            /*  IDCMP flags                                  */
  535. | REFRESHWINDOW
  536. | MOUSEBUTTONS
  537. | MENUPICK
  538. | REQCLEAR
  539. | GADGETDOWN
  540. | SELECTDOWN
  541. | SELECTUP,
  542.                          /*  Regular flags for gadgets and such           */
  543.   WINDOWDEPTH
  544. | WINDOWDRAG
  545. | REPORTMOUSE
  546. | WINDOWCLOSE
  547. | SMART_REFRESH,
  548.  
  549.   NULL,                  /* No gadgets for now                            */
  550.   NULL,                  /* User checkmark                                */
  551.   (UBYTE *) "Sprite Editor", /* Window Title                              */
  552.   NULL,                  /* Pointer to screen (Set later)                 */
  553.   NULL,                  /* Pointer to superbitmap                        */
  554.   0, 0, 320, 186,        /* Ignored because not sizeable                  */
  555.   WBENCHSCREEN,          /* Using the Workbench screen                    */
  556.   };
  557.  
  558. /***************************************************************************
  559.                   M A I N     P R O G R A M     M O D U L E
  560. ***************************************************************************/
  561. VOID main()
  562. {
  563.      ULONG    class;     /* Message class from Intuition                  */
  564.      USHORT   code;      /* Menu code info from Intuition                 */
  565.  
  566. /***************************************************************************
  567.            Read in the libraries,  and set each "read" mask bit.
  568. ***************************************************************************/
  569.  
  570.    if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0)))
  571.    {
  572.       (VOID) printf("no graphics library!!!\n");
  573.       close_things();
  574.       exit(1);
  575.    }
  576.    mask |= GRAPHICS;
  577.  
  578.  if(!(IntuitionBase = (struct IntuitionBase *)
  579.        OpenLibrary("intuition.library",0)))
  580.    {
  581.       (VOID) printf("no intuition here!!\n");
  582.       close_things();
  583.       exit(2);
  584.    }
  585.    mask |= INTUITION;
  586.  
  587. /***************************************************************************
  588.                 OPEN UP THE WINDOW ON TOP OF WORKBENCH SCREEN
  589. ***************************************************************************/
  590.  
  591.    if (!(w = (struct Window *)OpenWindow(&nw) ))
  592.    {
  593.       (VOID) printf("could not open the window\n");
  594.       close_things();
  595.       exit(3);
  596.    }
  597.    mask |= WINDOW;
  598.  
  599. /***************************************************************************
  600.                           CREATE THE THREE MENUS
  601. ***************************************************************************/
  602.  
  603.    NewMenu( &fmenu, filemenu_names, file_items, file_names,
  604.             NUM_FILE_ITEMS, item_widths[0], BOX_FILL);
  605.  
  606.    NewMenu( &win_menu, wind_names, win_items, win_text,
  607.             NUM_WINDOWS, item_widths[1], BLACK_FILL);
  608.  
  609.    NewMenu( &req_menu, rqs_names, req_items, req_names,
  610.            NUM_REQUESTS, item_widths[2], HAS_CHECKS);
  611.  
  612.    mask |= MENU;
  613.  
  614. /***************************************************************************
  615.                           INITIALIZATION CODE HERE
  616. ***************************************************************************/
  617.  
  618.    (VOID) SetMenuStrip(w, &fmenu);      /* Set up the menu here            */
  619.    (VOID) InitRequester(&req);          /* Init the requestor              */
  620.    (VOID) InitRequester(&gag);          /* Init Bit imaage requester       */
  621.    rp = w->RPort;
  622.  
  623. /* Init the fields in the Requester structure */
  624.  
  625.    req.LeftEdge  = 20;
  626.    req.TopEdge   = 20;
  627.    req.Width     = 250;
  628.    req.Height    = 80;
  629.    req.ReqGadget = &ongad;        /* First gadget */
  630.    req.ReqText   = &text;         /* Text for requester */
  631.    req.BackFill  = 1;             /* BackGnd color to window */
  632.    req.Flags     = 0;
  633.    req.ReqBorder = &out_border;  /* Must have at least one */
  634.  
  635. /* Init the fields in the Bit Image structure */
  636.  
  637.    gag.LeftEdge  = 20;
  638.    gag.TopEdge   = 20;
  639.    gag.Width     = 250;
  640.    gag.Height    = 80;
  641.    gag.ReqGadget = &stab;         /* First gadget */
  642.    gag.ReqText   = &imag_text;    /* Text for requester */
  643.    gag.BackFill  = 1;             /* BackGnd color to window */
  644.    gag.Flags     = 0;
  645.    gag.ReqBorder = &out_border;   /* Must have at least one */
  646.  
  647. /***************************************************************************
  648.                            MAIN PROGRAM LOOP HERE
  649. ***************************************************************************/
  650.    for (;;)
  651.    {
  652.  
  653.       if ((message = (struct IntuiMessage *)GetMsg(w->UserPort)) == 0L)  {
  654.           (VOID) Wait(1L<<w->UserPort->mp_SigBit);
  655.           continue;
  656.       }
  657.         class = message->Class;
  658.         code = message->Code;
  659.         (VOID) ReplyMsg(message);
  660.         switch (class) {
  661.  
  662.            case CLOSEWINDOW : close_things();
  663.                               exit(0);
  664.                               break;
  665.  
  666.            case MENUPICK    : if (MENUNUM(code) != MENUNULL)
  667.                                 domenu(MENUNUM(code), ITEMNUM(code));
  668.                               break;
  669.  
  670.            case MOUSEBUTTONS: break;
  671.         }   /* Case */
  672.    }  /* for */
  673. }   /* End of Main */
  674.  
  675. /***************************************************************************
  676.                    C R E A T E    A    N E W    M E N U
  677. ***************************************************************************/
  678. static VOID NewMenu ( menu, item_names,  menu_items, menu_text, num_items,
  679.               Mwidth, flag)
  680.  
  681. struct Menu      *menu;           /* Menu structure                       */
  682. char            *item_names[];    /* Pointer to array of item names       */
  683. struct MenuItem  menu_items[];    /* pointer to array of structures       */
  684. struct IntuiText menu_text[];     /* Pointer to array of text structures  */
  685. int               num_items;      /* Number of items                      */
  686. int               Mwidth;         /* Menu Width */
  687. int                 flag;         /* Special Item flag for ALL items */
  688. {
  689.     int i;
  690.     int height = 0;
  691.  
  692.     for (i=0; i< num_items; i++) {
  693.  
  694.           menu_text[i] = generic;              /* stamp generic template */
  695.           menu_text[i].IText = (UBYTE *) item_names[i];  /* mv string ptrs */
  696.           menu_items[i].NextItem = &menu_items[i+1];  /* Lnk to nxt item */
  697.           menu_items[i].TopEdge = 10 * i;            /* Top rect of item */
  698.           menu_items[i].LeftEdge = 0;
  699.           menu_items[i].Height = 8;
  700.           menu_items[i].ItemFill = (APTR)&menu_text[i];
  701.           menu_items[i].Flags = flag;
  702.           menu_items[i].Width = Mwidth;
  703.           menu_items[i].MutualExclude = 0x0000;
  704.           menu_items[i].Command = 0;
  705.           menu_items[i].SubItem = NL;
  706.           menu_items[i].NextSelect = NL;
  707.           height += 10;
  708.     }
  709.     menu_items[num_items-1].NextItem = NULL;
  710.     menu->Height = height;
  711. }
  712. /***************************************************************************
  713.                         DO THE MENU SELECTIONS
  714. ***************************************************************************/
  715. static VOID domenu(menu, item)
  716. USHORT menu, item;
  717. {
  718.     switch (menu) {
  719.       case FILE_MENU: switch (item) {
  720.                       case   NEW_ITEM: (VOID) printf("Opening new file\n");
  721.                              break;
  722.             case  OPEN_ITEM: (VOID) printf("Opening file\n");
  723.                              break;
  724.             case  SAVE_ITEM: (VOID) printf("Saving file\n");
  725.                              break;
  726.             case SAVAS_ITEM: (VOID) printf("Saving as..\n");
  727.                              break;
  728.             case  QUIT_ITEM: close_things();
  729.                              exit(0);  break;
  730.                    } break;
  731.  
  732.       case WIND_MENU: switch (item) {
  733.                            case  INFO_ITEM: (VOID) printf("Information window\n");
  734.                              break;
  735.             case   GRA_ITEM: (VOID) DrawImage (rp, &tong_face, 30L, 30L);
  736.                              (VOID) DrawImage (rp, &smil_face, 64L, 30L);
  737.                              break;
  738.                         } break;
  739.  
  740.       case REQS_MENU: switch (item) {
  741.             case      REQS1: auto_req ( "Here is an Auto requestor");
  742.                              break;
  743.             case      REQS2: auto_req ( "And yet another one" );
  744.                              break;
  745.             case      REQS3: auto_req ( "How about one more" );
  746.                              break;
  747.  
  748.             case   GAD_REQS: if (we_add) {
  749.                                  (VOID) AddGadget(w, &JoyGadget, -1 );
  750.                                  (VOID) RefreshGadgets(&JoyGadget,w,NULL);
  751.                                  we_add = FALSE;
  752.                              }
  753.                              break;
  754.  
  755.             case   TEX_REQS: if (Request(&req, w) == 1)
  756.                                do_req();
  757.                              break;
  758.  
  759.             case   IMG_REQS: if (Request(&gag, w) == 1)
  760.                                do_req();
  761.                              break;
  762.  
  763.                         } break;
  764.     }
  765. }
  766.  
  767. /***************************************************************************
  768.                             HANDLE AUTO-REQUESTS
  769. ***************************************************************************/
  770. static VOID auto_req (textp)
  771. char *textp;         /* Pointer to the text */
  772. {
  773.    int   val;
  774.    AutoText.IText = (UBYTE *) textp;            /* Text pointer          */
  775.  
  776.   val = AutoRequest(w, &AutoText, &TRUEtext, &FALSEtext, 0L, 0L, 319L, 60L );
  777.   if (val)
  778.        (VOID) printf("TRUE\n");
  779.    else
  780.        (VOID) printf("FALSE\n");
  781. }
  782.  
  783. /***************************************************************************
  784.                    D O   C U S T O M    R E Q U E S T
  785. ***************************************************************************/
  786.  
  787. static VOID do_req()
  788. {
  789.       int looping = TRUE;
  790.       struct IntuiMessage *mes;
  791.       struct Gadget *gad;           /* Gadget chosen */
  792.       ULONG class;
  793.  
  794.       while (looping)
  795.       {
  796.           if ((mes = (struct IntuiMessage *)GetMsg(w->UserPort)) == 0L) {
  797.              (VOID) Wait(1L<<w->UserPort->mp_SigBit);
  798.              continue;
  799.           }
  800.           class = mes->Class;
  801.           gad = (struct Gadget *)mes->IAddress;
  802.           (VOID) ReplyMsg(mes);
  803.           if (class == REQCLEAR) {
  804.              looping = FALSE;
  805.           }
  806.           if (class == GADGETDOWN) {
  807.  
  808.              switch (gad->GadgetID) {
  809.  
  810.                 case TRUE_BUTT:  (VOID) printf("true button ...\n");
  811.                                  break;
  812.                 case FALSE_BUTT: (VOID) printf("false button...\n");
  813.                                  break;
  814.                 case FACE:       (VOID) printf("Ouch!!..That hurt!!\n");
  815.                                  break;
  816.              }
  817.           }
  818.       }
  819. }
  820.  
  821. /***************************************************************************
  822.                      C L O S E      T H I N G S
  823. ***************************************************************************/
  824.  
  825. static VOID close_things()
  826. {
  827.    if (mask & MENU)      (VOID) ClearMenuStrip(w, &fmenu);
  828.    if (mask & WINDOW)    (VOID) CloseWindow(w);
  829.    if (mask & GRAPHICS)  (VOID) CloseLibrary((VOID *)GfxBase);
  830.    (VOID) OpenWorkBench();
  831.    if (mask & INTUITION) (VOID) CloseLibrary((VOID *)IntuitionBase);
  832. }
  833.  
  834. /***************************************************************************
  835.                          DIAGNOSTIC DUMP ROUTINE
  836. ***************************************************************************/
  837. #ifdef DEADCODE        /* Currently not used for anything */
  838. #define BPL 16
  839. static VOID dump(adr,len)
  840. long adr, len;
  841. {
  842.         unsigned char    *strtchr,*endchr,*cnt;
  843.  
  844.         endchr = (unsigned char *) (adr + len -1);
  845.         for (strtchr = (unsigned char *) adr;
  846.            strtchr <= endchr; strtchr += BPL) {
  847.                 (VOID) printf("%06lx: ",(long) strtchr);
  848.                 for (cnt = strtchr; cnt < strtchr + BPL; cnt++)
  849.                         (VOID) printf(" %02x",(int) *cnt);
  850.                 (VOID) printf("    ");
  851.                 for (cnt = strtchr; cnt < strtchr + BPL; cnt++)
  852.                         if ((*cnt & 0x7f) < 32)
  853.                                 (VOID) printf(".");
  854.                         else
  855.                                 (VOID) printf("%c", *cnt);
  856.                 (VOID) printf("\n");
  857.         }
  858. }
  859. #endif    /* DEADCODE */
  860.